'''
Created on Apr 9, 2012
TC ID: 5004
Desc: Kiem thu chuc nang sua thong tin bai hoc
@author: lavang
'''
import unittest
import time
import HTMLTestRunner
from Functions.globalFunc import preCondition, endCondition, readData
from Functions.loginPageFunc import login
from Functions.administratorFunc import clickOnBtnLessons
from Functions.lessonsFunc import createLesson,\
    verifyLessonCreatedSuccessfully, clickOnLessonLink

username = readData("username")
password = readData("password")
nameLesson = readData("lessonName",index=1)
lessonLink=readData("lessonName",index=2)
language = readData("language")
categoriesName = readData("categoriesLesson")
price = readData("priceLesson")


class Ecom_5004(unittest.TestCase):


    def setUp(self):
        print "Buoc 1: Mo Website"
        preCondition(self)

    def test_Ecom_5004(self):
        print "Buoc 2: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 3: Click vao lessons button"
        clickOnBtnLessons(self)
        
        print "Buoc 4: Click vao bai hoc muon sua"
        clickOnLessonLink(self,nameLesson)
        
        print "Buoc 5: Sua thong tin"
        createLesson(self, nameLesson = lessonLink, language = language, categories = categoriesName, price = price)
        
        print "Buoc 6: Kiem tra bai hoc duoc sua thong tin thanh cong"
        self.assertTrue(verifyLessonCreatedSuccessfully(self,lessonLink), "Failed: Sua thong tin khong thanh cong")
        print "Passed: Sua thong tin bai hoc thanh cong"
        
    def tearDown(self):
        print "Buoc 7: Dong website"
        endCondition(self)
    


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5004)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang sua thong tin bai hoc'
                    )
    runner.run(suite)